import * as React from "react"
import { getServerSession } from "next-auth/next"
import { authOptions } from "@/app/api/auth/[...nextauth]/route"
import { Shell } from "@/components/shell"
import { getVendorContractReviews } from "@/lib/general-contracts/service"
import { VendorGeneralContractReviewTable } from "./vendor-general-contract-review-table"
import { InformationButton } from "@/components/information/information-button"
import { unstable_noStore as noStore } from 'next/cache'

export default async function VendorGeneralContractReviewPage() {
  noStore()
  
  const session = await getServerSession(authOptions)
  
  if (!session?.user?.companyId) {
    return (
      <div className="flex h-full items-center justify-center p-6">
        정상적인 벤더에 소속된 계정이 아닙니다.
      </div>
    )
  }

  const vendorId = session.user.companyId

  // 데이터 가져오기
  const contractReviews = await getVendorContractReviews(vendorId, 1, 100, '')

  return (
    <Shell className="gap-6">
      <div className="flex items-center justify-between">
        <div>
          <div className="flex items-center gap-2">
            <h2 className="text-2xl font-bold tracking-tight">
              일반계약 조건검토
            </h2>
            <InformationButton pagePath="partners/general-contract-review" />
          </div>
          <p className="text-muted-foreground">
            조건검토 요청된 계약 목록을 확인하고 검토합니다.
          </p>
        </div>
      </div>

      <VendorGeneralContractReviewTable data={contractReviews.data} />
    </Shell>
  )
}

